package com.shyb.lingxian.netWork;

import java.io.IOException;
import java.util.concurrent.TimeUnit;

import okhttp3.Interceptor;
import okhttp3.OkHttpClient;
import okhttp3.Request;
import okhttp3.Response;
import retrofit2.Retrofit;
import retrofit2.adapter.rxjava.RxJavaCallAdapterFactory;
import retrofit2.converter.gson.GsonConverterFactory;

/**
 * Created by gs on 2018/3/23.
 */

public class NetWorkClient {



    public static Retrofit request(String url) {

        OkHttpClient client = new OkHttpClient.Builder()
                .addInterceptor(new Interceptor() {
                    @Override
                    public Response intercept(Interceptor.Chain chain) throws IOException {
                        Request request = chain.request();
                        Request.Builder builder = request.newBuilder();
                        Request build = builder
//                                .addHeader("X-Parse-Cid", Const.getCID())
//                                .addHeader("X-Parse-User-Id", Const.getUserID())
//                                .addHeader("X-Parse-Session-Token", Const.getToken())
//                                .addHeader("imei",Const.getImei())
                                .build();
                        return chain.proceed(build);
                    }
                }).retryOnConnectionFailure(true)
                .connectTimeout(5, TimeUnit.SECONDS)
                .build();
        return new Retrofit.Builder()
                .baseUrl(url)
                .client(client)
                .addConverterFactory(GsonConverterFactory.create())
                .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
                .build();

//        {
//            return new Retrofit.Builder()
//                    .baseUrl(url)
//                    .addConverterFactory(GsonConverterFactory.create())
//                    .addCallAdapterFactory(RxJavaCallAdapterFactory.create())
//                    .build();
//        }

    }
}
